package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysOssConfig;
import com.ruoyi.system.service.ISysOssConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 存储配置Controller
 * 
 * @author zouhuu
 * @date 2022-07-24
 */
@RestController
@RequestMapping("/system/ossConfig")
public class SysOssConfigController extends BaseController
{
    @Autowired
    private ISysOssConfigService sysOssConfigService;

    /**
     * 查询存储配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:oss:config')")
    @GetMapping("/list")
    public TableDataInfo list(SysOssConfig sysOssConfig)
    {
        startPage();
        List<SysOssConfig> list = sysOssConfigService.selectSysOssConfigList(sysOssConfig);
        return getDataTable(list);
    }

    /**
     * 导出存储配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:oss:config')")
    @Log(title = "存储配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOssConfig sysOssConfig)
    {
        List<SysOssConfig> list = sysOssConfigService.selectSysOssConfigList(sysOssConfig);
        ExcelUtil<SysOssConfig> util = new ExcelUtil<SysOssConfig>(SysOssConfig.class);
        util.exportExcel(response, list, "存储配置数据");
    }

    /**
     * 获取存储配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:oss:config')")
    @GetMapping(value = "/{ossConfigId}")
    public AjaxResult getInfo(@PathVariable("ossConfigId") Long ossConfigId)
    {
        return AjaxResult.success(sysOssConfigService.selectSysOssConfigByOssConfigId(ossConfigId));
    }

    /**
     * 新增存储配置
     */
    @PreAuthorize("@ss.hasPermi('system:oss:config')")
    @Log(title = "存储配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysOssConfig sysOssConfig)
    {
        return toAjax(sysOssConfigService.insertSysOssConfig(sysOssConfig));
    }

    /**
     * 修改存储配置
     */
    @PreAuthorize("@ss.hasPermi('system:oss:config')")
    @Log(title = "存储配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysOssConfig sysOssConfig)
    {
        return toAjax(sysOssConfigService.updateSysOssConfig(sysOssConfig));
    }

    /**
     * 删除存储配置
     */
    @PreAuthorize("@ss.hasPermi('system:oss:config')")
    @Log(title = "存储配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ossConfigIds}")
    public AjaxResult remove(@PathVariable Long[] ossConfigIds)
    {
        return toAjax(sysOssConfigService.deleteSysOssConfigByOssConfigIds(ossConfigIds));
    }
}
